// pages/finance/withdraw/index/index.js
var http = require('../../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tableHeader: [
      "时间", "金额", "状态", "操作"
    ],
    totalPage: 0,
    form: {
      page: 1,
      size: 15,
      start_time: '',//提现记录开始时间
      end_time: '',//提现记录结束时间
    },
    tableList: []
  },
  //获取表单，并对表单进行处理后进行查找
  search(e) {
    if (e.detail.start_date === "开始日期" || e.detail.end_date === "结束日期") {
      delete this.data.form.pay_datetime;
    } else {
      this.setData({
        "form.start_time": e.detail.start_date
      });
      this.setData({
        "form.end_time": e.detail.end_date
      });
    }
    this.setData({
      "form.page": 1
    });
    this.setData({
      "tableList": []
    });

    this.getWithdrawList();
  },
  //获取提现记录
  getWithdrawList() {
    let that = this;
    let list = this.data.tableList;
    wx.showLoading({
      title: 'loading'
    });
    http.GET({
      url: 'api/user/withdrawOrderList',
      data: that.data.form,
      success: function (res) {
        wx.hideLoading();
        if (res.data.error === 0) {
          that.setData({
            'totalPage': res.data.data.last_page
          });
          let newList = res.data.data.data;
          for (let index = 0; index < newList.length; index++) {
            list.push(newList[index]);
          }
          that.setData({
            "tableList": list
          });
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none'
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      "tableList": []
    });
    this.getWithdrawList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.form.page < this.data.totalPage) {
      let page = ++this.data.form.page;
      this.setData({
        "form.page": page
      });
      this.getWithdrawList();
    } else {
      wx.showToast({
        title: '已经到底了',
        icon: 'none'
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})